﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Terraria.World.Generation
{
	// Token: 0x0200006D RID: 109
	public static class Actions
	{
		// Token: 0x060009D4 RID: 2516 RVA: 0x003E55D8 File Offset: 0x003E37D8
		public static GenAction Chain(params GenAction[] actions)
		{
			for (int i = 0; i < actions.Length - 1; i++)
			{
				actions[i].NextAction = actions[i + 1];
			}
			return actions[0];
		}

		// Token: 0x060009D5 RID: 2517 RVA: 0x0000AA16 File Offset: 0x00008C16
		public static GenAction Continue(GenAction action)
		{
			return new Actions.ContinueWrapper(action);
		}

		// Token: 0x0200006E RID: 110
		public class ContinueWrapper : GenAction
		{
			// Token: 0x060009D6 RID: 2518 RVA: 0x0000AA1E File Offset: 0x00008C1E
			public ContinueWrapper(GenAction action)
			{
				this._action = action;
			}

			// Token: 0x060009D7 RID: 2519 RVA: 0x0000AA2D File Offset: 0x00008C2D
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				this._action.Apply(origin, x, y, args);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E88 RID: 3720
			private GenAction _action;
		}

		// Token: 0x0200006F RID: 111
		public class Count : GenAction
		{
			// Token: 0x060009D8 RID: 2520 RVA: 0x0000AA4B File Offset: 0x00008C4B
			public Count(Ref<int> count)
			{
				this._count = count;
			}

			// Token: 0x060009D9 RID: 2521 RVA: 0x0000AA5A File Offset: 0x00008C5A
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				this._count.Value++;
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E89 RID: 3721
			private Ref<int> _count;
		}

		// Token: 0x02000070 RID: 112
		public class Scanner : GenAction
		{
			// Token: 0x060009DA RID: 2522 RVA: 0x0000AA7A File Offset: 0x00008C7A
			public Scanner(Ref<int> count)
			{
				this._count = count;
			}

			// Token: 0x060009DB RID: 2523 RVA: 0x0000AA89 File Offset: 0x00008C89
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				this._count.Value++;
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E8A RID: 3722
			private Ref<int> _count;
		}

		// Token: 0x02000071 RID: 113
		public class TileScanner : GenAction
		{
			// Token: 0x060009DC RID: 2524 RVA: 0x003E5608 File Offset: 0x003E3808
			public TileScanner(params ushort[] tiles)
			{
				this._tileIds = tiles;
				this._tileCounts = new Dictionary<ushort, int>();
				for (int i = 0; i < tiles.Length; i++)
				{
					this._tileCounts[this._tileIds[i]] = 0;
				}
			}

			// Token: 0x060009DD RID: 2525 RVA: 0x003E5650 File Offset: 0x003E3850
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				Tile tile = GenBase._tiles[x, y];
				if (tile.active() && this._tileCounts.ContainsKey(tile.type))
				{
					Dictionary<ushort, int> tileCounts;
					ushort type;
					(tileCounts = this._tileCounts)[type = tile.type] = tileCounts[type] + 1;
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x060009DE RID: 2526 RVA: 0x003E56B0 File Offset: 0x003E38B0
			public Actions.TileScanner Output(Dictionary<ushort, int> resultsOutput)
			{
				this._tileCounts = resultsOutput;
				for (int i = 0; i < this._tileIds.Length; i++)
				{
					if (!this._tileCounts.ContainsKey(this._tileIds[i]))
					{
						this._tileCounts[this._tileIds[i]] = 0;
					}
				}
				return this;
			}

			// Token: 0x060009DF RID: 2527 RVA: 0x0000AAA9 File Offset: 0x00008CA9
			public Dictionary<ushort, int> GetResults()
			{
				return this._tileCounts;
			}

			// Token: 0x060009E0 RID: 2528 RVA: 0x0000AAB1 File Offset: 0x00008CB1
			public int GetCount(ushort tileId)
			{
				if (!this._tileCounts.ContainsKey(tileId))
				{
					return -1;
				}
				return this._tileCounts[tileId];
			}

			// Token: 0x04000E8B RID: 3723
			private ushort[] _tileIds;

			// Token: 0x04000E8C RID: 3724
			private Dictionary<ushort, int> _tileCounts;
		}

		// Token: 0x02000072 RID: 114
		public class Blank : GenAction
		{
			// Token: 0x060009E1 RID: 2529 RVA: 0x0000AACF File Offset: 0x00008CCF
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				return base.UnitApply(origin, x, y, args);
			}
		}

		// Token: 0x02000073 RID: 115
		public class Custom : GenAction
		{
			// Token: 0x060009E3 RID: 2531 RVA: 0x0000AAE4 File Offset: 0x00008CE4
			public Custom(GenBase.CustomPerUnitAction perUnit)
			{
				this._perUnit = perUnit;
			}

			// Token: 0x060009E4 RID: 2532 RVA: 0x003E5704 File Offset: 0x003E3904
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				bool flag = this._perUnit(x, y, args);
				return flag | base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E8D RID: 3725
			private GenBase.CustomPerUnitAction _perUnit;
		}

		// Token: 0x02000074 RID: 116
		public class ClearMetadata : GenAction
		{
			// Token: 0x060009E5 RID: 2533 RVA: 0x0000AAF3 File Offset: 0x00008CF3
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].ClearMetadata();
				return base.UnitApply(origin, x, y, args);
			}
		}

		// Token: 0x02000075 RID: 117
		public class Clear : GenAction
		{
			// Token: 0x060009E7 RID: 2535 RVA: 0x0000AB11 File Offset: 0x00008D11
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].ClearEverything();
				return base.UnitApply(origin, x, y, args);
			}
		}

		// Token: 0x02000076 RID: 118
		public class ClearTile : GenAction
		{
			// Token: 0x060009E9 RID: 2537 RVA: 0x0000AB2F File Offset: 0x00008D2F
			public ClearTile(bool frameNeighbors = false)
			{
				this._frameNeighbors = frameNeighbors;
			}

			// Token: 0x060009EA RID: 2538 RVA: 0x0000AB3E File Offset: 0x00008D3E
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				WorldUtils.ClearTile(x, y, this._frameNeighbors);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E8E RID: 3726
			private bool _frameNeighbors;
		}

		// Token: 0x02000077 RID: 119
		public class ClearWall : GenAction
		{
			// Token: 0x060009EB RID: 2539 RVA: 0x0000AB58 File Offset: 0x00008D58
			public ClearWall(bool frameNeighbors = false)
			{
				this._frameNeighbors = frameNeighbors;
			}

			// Token: 0x060009EC RID: 2540 RVA: 0x0000AB67 File Offset: 0x00008D67
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				WorldUtils.ClearWall(x, y, this._frameNeighbors);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E8F RID: 3727
			private bool _frameNeighbors;
		}

		// Token: 0x02000078 RID: 120
		public class HalfBlock : GenAction
		{
			// Token: 0x060009ED RID: 2541 RVA: 0x0000AB81 File Offset: 0x00008D81
			public HalfBlock(bool value = true)
			{
				this._value = value;
			}

			// Token: 0x060009EE RID: 2542 RVA: 0x0000AB90 File Offset: 0x00008D90
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].halfBrick(this._value);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E90 RID: 3728
			private bool _value;
		}

		// Token: 0x02000079 RID: 121
		public class SetTile : GenAction
		{
			// Token: 0x060009EF RID: 2543 RVA: 0x0000ABB4 File Offset: 0x00008DB4
			public SetTile(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
			{
				this._type = type;
				this._doFraming = setSelfFrames;
				this._doNeighborFraming = setNeighborFrames;
			}

			// Token: 0x060009F0 RID: 2544 RVA: 0x0000ABD1 File Offset: 0x00008DD1
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].ResetToType(this._type);
				if (this._doFraming)
				{
					WorldUtils.TileFrame(x, y, this._doNeighborFraming);
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E91 RID: 3729
			private ushort _type;

			// Token: 0x04000E92 RID: 3730
			private bool _doFraming;

			// Token: 0x04000E93 RID: 3731
			private bool _doNeighborFraming;
		}

		// Token: 0x0200007A RID: 122
		public class DebugDraw : GenAction
		{
			// Token: 0x060009F1 RID: 2545 RVA: 0x0000AC0A File Offset: 0x00008E0A
			public DebugDraw(SpriteBatch spriteBatch, Color color = default(Color))
			{
				this._spriteBatch = spriteBatch;
				this._color = color;
			}

			// Token: 0x060009F2 RID: 2546 RVA: 0x003E5730 File Offset: 0x003E3930
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				this._spriteBatch.Draw(Main.magicPixel, new Rectangle((x << 4) - (int)Main.screenPosition.X, (y << 4) - (int)Main.screenPosition.Y, 16, 16), this._color);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E94 RID: 3732
			private Color _color;

			// Token: 0x04000E95 RID: 3733
			private SpriteBatch _spriteBatch;
		}

		// Token: 0x0200007B RID: 123
		public class SetSlope : GenAction
		{
			// Token: 0x060009F3 RID: 2547 RVA: 0x0000AC20 File Offset: 0x00008E20
			public SetSlope(int slope)
			{
				this._slope = slope;
			}

			// Token: 0x060009F4 RID: 2548 RVA: 0x0000AC2F File Offset: 0x00008E2F
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				WorldGen.SlopeTile(x, y, this._slope);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E96 RID: 3734
			private int _slope;
		}

		// Token: 0x0200007C RID: 124
		public class SetHalfTile : GenAction
		{
			// Token: 0x060009F5 RID: 2549 RVA: 0x0000AC4A File Offset: 0x00008E4A
			public SetHalfTile(bool halfTile)
			{
				this._halfTile = halfTile;
			}

			// Token: 0x060009F6 RID: 2550 RVA: 0x0000AC59 File Offset: 0x00008E59
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].halfBrick(this._halfTile);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E97 RID: 3735
			private bool _halfTile;
		}

		// Token: 0x0200007D RID: 125
		public class PlaceTile : GenAction
		{
			// Token: 0x060009F7 RID: 2551 RVA: 0x0000AC7D File Offset: 0x00008E7D
			public PlaceTile(ushort type, int style = 0)
			{
				this._type = type;
				this._style = style;
			}

			// Token: 0x060009F8 RID: 2552 RVA: 0x0000AC93 File Offset: 0x00008E93
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				WorldGen.PlaceTile(x, y, (int)this._type, true, false, -1, this._style);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E98 RID: 3736
			private ushort _type;

			// Token: 0x04000E99 RID: 3737
			private int _style;
		}

		// Token: 0x0200007E RID: 126
		public class RemoveWall : GenAction
		{
			// Token: 0x060009F9 RID: 2553 RVA: 0x0000ACB7 File Offset: 0x00008EB7
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].wall = 0;
				return base.UnitApply(origin, x, y, args);
			}
		}

		// Token: 0x0200007F RID: 127
		public class PlaceWall : GenAction
		{
			// Token: 0x060009FB RID: 2555 RVA: 0x0000ACD6 File Offset: 0x00008ED6
			public PlaceWall(byte type, bool neighbors = true)
			{
				this._type = type;
				this._neighbors = neighbors;
			}

			// Token: 0x060009FC RID: 2556 RVA: 0x003E5788 File Offset: 0x003E3988
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].wall = (ushort)this._type;
				WorldGen.SquareWallFrame(x, y, true);
				if (this._neighbors)
				{
					WorldGen.SquareWallFrame(x + 1, y, true);
					WorldGen.SquareWallFrame(x - 1, y, true);
					WorldGen.SquareWallFrame(x, y - 1, true);
					WorldGen.SquareWallFrame(x, y + 1, true);
				}
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E9A RID: 3738
			private byte _type;

			// Token: 0x04000E9B RID: 3739
			private bool _neighbors;
		}

		// Token: 0x02000080 RID: 128
		public class SetLiquid : GenAction
		{
			// Token: 0x060009FD RID: 2557 RVA: 0x0000ACEC File Offset: 0x00008EEC
			public SetLiquid(int type = 0, byte value = 255)
			{
				this._value = value;
				this._type = type;
			}

			// Token: 0x060009FE RID: 2558 RVA: 0x0000AD02 File Offset: 0x00008F02
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				GenBase._tiles[x, y].liquidType(this._type);
				GenBase._tiles[x, y].liquid = this._value;
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E9C RID: 3740
			private int _type;

			// Token: 0x04000E9D RID: 3741
			private byte _value;
		}

		// Token: 0x02000081 RID: 129
		public class SwapSolidTile : GenAction
		{
			// Token: 0x060009FF RID: 2559 RVA: 0x0000AD3D File Offset: 0x00008F3D
			public SwapSolidTile(ushort type)
			{
				this._type = type;
			}

			// Token: 0x06000A00 RID: 2560 RVA: 0x003E57F0 File Offset: 0x003E39F0
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				Tile tile = GenBase._tiles[x, y];
				if (WorldGen.SolidTile(tile))
				{
					tile.ResetToType(this._type);
					return base.UnitApply(origin, x, y, args);
				}
				return base.Fail();
			}

			// Token: 0x04000E9E RID: 3742
			private ushort _type;
		}

		// Token: 0x02000082 RID: 130
		public class SetFrames : GenAction
		{
			// Token: 0x06000A01 RID: 2561 RVA: 0x0000AD4C File Offset: 0x00008F4C
			public SetFrames(bool frameNeighbors = false)
			{
				this._frameNeighbors = frameNeighbors;
			}

			// Token: 0x06000A02 RID: 2562 RVA: 0x0000AD5B File Offset: 0x00008F5B
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				WorldUtils.TileFrame(x, y, this._frameNeighbors);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000E9F RID: 3743
			private bool _frameNeighbors;
		}

		// Token: 0x02000083 RID: 131
		public class Smooth : GenAction
		{
			// Token: 0x06000A03 RID: 2563 RVA: 0x0000AD75 File Offset: 0x00008F75
			public Smooth(bool applyToNeighbors = false)
			{
				this._applyToNeighbors = applyToNeighbors;
			}

			// Token: 0x06000A04 RID: 2564 RVA: 0x0000AD84 File Offset: 0x00008F84
			public override bool Apply(Point origin, int x, int y, params object[] args)
			{
				Tile.SmoothSlope(x, y, this._applyToNeighbors);
				return base.UnitApply(origin, x, y, args);
			}

			// Token: 0x04000EA0 RID: 3744
			private bool _applyToNeighbors;
		}
	}
}
